<?php
define('BLOCKCHAT','1.00');

/************************************************************************/
/* FrameWork  test preview                                              */
/* ==================================================================== */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/

autostyle("$path/$block");

//carica la lingua se esiste
$lang=lang();
if (file_exists("$path/$block/lang/$lang.inc"))
    include "$path/$block/lang/$lang.inc";
else
    include "$path/$block/lang/it.inc";


$appname=$_GET['appname'];
$opt=$_POST['chat_opt'];
$listchat="extras/txtshout/listchat.txt";
if(!file_exists($listchat))$listchat="http://www.sdlbasic.org/main/txtshout/listchat.txt";

$l=file("$listchat");
for ($i=0; $i< count($l); $i++){
    if ($l[$i]!=""){
	$t=explode("=",$l[$i]);
	if ($opt=="")$opt=$t[0];
	$basechat_opt[$t[0]]=substr($t[1],0,-1);
    }
}
$basechat=$basechat_opt[$opt];

$user=user_getuser();
?>

<script language="JavaScript">
var ID;
var basechat;
var el;

function popSmilies(){
  window.open(basechat + "smilies.php","smilies","width=180,height=400,toolbar=no,status=no,resizable=yes,scrollbars=yes");
}
function checkLength(x) {
  maxMsgLength = 300;
  if (x.value.length > maxMsgLength) {
    x.value = x.value.substring(0, maxMsgLength);
  }
}


function start_autorefresh(){
    ID=window.setTimeout("update();",1000);
}

function update(){
    parent.shoutframe.location=basechat+'index.php';
    if( document.refresh.arefresh.checked != false)
	ID=window.setTimeout("update();",10000);
}


</script>
<!-- END txtShout -->

<?php structure_openBlock("table block right chat",_CHAT,"$path/$block"); ?>

	<form class='selchat' name='selchat' action='index.php?appname=<?=$appname;?>' method='POST'>
		<select name='chat_opt'>
			<option><?=$opt?></option>
			<?php
			    foreach( array_keys($basechat_opt) as $optsel){
				if($optsel!=$opt)
				    echo("<option>$optsel</option>\n");
			    }
			?>
		</select>
		<input type='submit' value='<?=_GO?>' />
	</form>

	<iframe name="shoutframe" src="<?=$basechat ?>index.php" scrolling="yes" allowtransparency="yes" style="width: 94%" ></iframe>

	<form class='autorefresh' name="refresh">
		<input type='checkbox' name='arefresh' onClick="javascript:basechat='<?=trim($basechat); ?>'; start_autorefresh(); " /><?=_AUTOREFRESH?>
	</form>

	<div class='links'>
		<a href="http://txtbox.co.za" target="_blank"><?=_TXTSHOUT?></a>
	</div>

      <?php if ($user) { ?>
	<form class='insert' name="shoutform" action="<?=$basechat ?>shout.php" method="post" target="shoutframe">
		<input type='hidden' name='ts_nm' value='<?=$user?>' />
		<textarea name="ts_mg" cols="15" rows="3" style="width:98%; border: #000000 1px solid; background-color: #ECF0F3;font-family: Arial, sans-serif; font-size: 8pt;" onKeyUp="checkLength(this)"></textarea>

		<div class='buttons'>
			<input type="submit" name="sub" value="send" />
			<input type="reset" name="clear" value="clear" />
			<a href="<?=$basechat;?>index.php" target="shoutframe"><?=_REFRESH;?></a>
		</div>
	</form>

<?php } ?>

<?php structure_closeBlock(); ?>

<script language="JavaScript">
basechat='<?=trim($basechat); ?>';
if( document.refresh.arefresh.checked != false)
    ID=window.setTimeout("update();",10000);
</script>
